// Huffman.h
// Written By Hatem Mostafa, 4 Jan 2005 (from CodeProject: http://www.codeproject.com/KB/recipes/Huffman_coding.aspx)
// Modified as C By klauski, 19, Nov, 2011
//////////////////////////////////////////////////////////////////////

#ifndef __COMPRESS_H__
#define __COMPRESS_H__

#include "stddef.h"

typedef unsigned char UBYTE;
typedef unsigned long DWORD;

typedef struct HuffmanNode_struct
{
	UBYTE byAscii;
	char ofsParent, ofsLeft, ofsRight; // 4 bytes
} HuffmanNode;

#define AccessHuffmanNode(init, offset) \
	((HuffmanNode*)((unsigned char*)init + (offset * sizeof(HuffmanNode))))

typedef struct HuffmanTree_struct
{
	HuffmanNode* nodes;
	int count;
} HuffmanTree;

#ifdef WINDOWS_MAKE

BOOL CompressHuffman(BYTE *pSrc, int nSrcLen, BYTE **pDes, int *nDesLen);
BOOL CompressDifferentialHuffman(BYTE *pSrc, int nSrcLen, BYTE **pDes, int *nDesLen);
BOOL CompressHuffmanUsingTree(BYTE *pSrc, int nSrcLen, BYTE **pDes, int *nDesLen);

#else

unsigned* ReadHuffmanTreeFromMemory();

#endif

void SetHuffmanTree(HuffmanTree tree);
HuffmanTree GetHuffmanTree(void);

BOOL DecompressHuffman(BYTE *pSrc, int nSrcLen, BYTE **pDes, int *nDesLen);
BOOL DecompressDifferentialHuffman(BYTE *pSrc, int nSrcLen, BYTE **pDes, int *nDesLen);
long /* the decompressed bits */
	DecompressHuffmanPartially(unsigned char *pDes, unsigned char *pSrc, long nWrittenDecompressedBits, long nTotalCompressedBits, int nDesLimits);
//void* GenerateHuffmanTree(BYTE* pSrc, int nSrcLen, UBYTE *pDesPtr, int* nHuffLen)

#endif